package glen.mgbean;

import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;

import javax.faces.context.FacesContext;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Map;

/**
 * Created by rachatanawee on 2/4/14.
 */
public class ReportViewer {
    private String reportId;
    private  byte[] reportByte;
    public String getReportId() {
        return reportId;
    }

    public void setReportId(String reportId) {
        this.reportId = reportId;
    }

    public StreamedContent getReportStream() throws IOException {
        FacesContext context = FacesContext.getCurrentInstance();
        Map<String, Object> session = context.getExternalContext().getSessionMap();
        reportByte=(byte[])session.get("productReport");
        if(reportByte==null)
            return null;
        //session.remove("productReport");
        return new DefaultStreamedContent(new ByteArrayInputStream(reportByte));
    }
}
